home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1997 September & October / Amiga-CD 1997 #9-10.iso / aminet / gameboyemulator / common.h < prev    next >
Text File  |  1995-10-29  |  3KB  |  116 lines

  1. /** VGB: portable GameBoy emulator ***************************/
  2. /**                                                         **/
  3. /**                        Common.h                         **/
  4. /**                                                         **/
  5. /** This file contains parts of the drivers which are       **/
  6. /** common for both Unix/X and MSDOS.                       **/
  7. /**                                                         **/
  8. /** Copyright (C) Marat Fayzullin 1995                      **/
  9. /**     You are not allowed to distribute this software     **/
  10. /**     commercially. Please, notify me, if you make any    **/   
  11. /**     changes to this file.                               **/
  12. /*************************************************************/
  13.  
  14.  
  15. /****************************************************************/
  16. /*** Refresh a line.                                          ***/
  17. /****************************************************************/
  18. void RefreshLine(byte Y)
  19. {
  20. /*    printf("XBuf1=%x\n",XBuf);
  21.     StartDisplay(Y);
  22.     printf("XBuf2=%x\n",XBuf);
  23. */
  24.  
  25.   register byte Offset,Mask,*P,*T,*R,D0,D1,X1,X2;
  26.  
  27.   R=XBuf+WIDTH*Y;
  28.     
  29.   if((LCDCONT&0x81)!=0x81)
  30.     for(X1=0;X1<WIDTH;X1++) *R++=Palette[0];
  31.   else
  32.   {
  33.     Offset=Y+SCROLLY;
  34.     T=BgdTab+((word)(Offset&0xF8)<<2);
  35.     Offset=(Offset&0x07)<<1;
  36.       
  37.     D0=*(T+(SCROLLX>>3));
  38.     if(~LCDCONT&0x10) D0+=0x80;
  39.     P=ChrGen+(D0<<4)+Offset;
  40.     D0=*P++;D1=*P;Mask=0x80>>(SCROLLX&0x07);   
  41.   
  42.     X1=SCROLLX;X2=SCROLLX+WIDTH;
  43.     while(X1!=X2)
  44.     {
  45.       *R=Palette[BPal[D0&Mask? (D1&Mask? 3:1):(D1&Mask? 2:0)]];
  46.       R++;X1++;
  47.       if(!(Mask>>=1))
  48.       {
  49.         D0=*(T+(X1>>3));
  50.         if(~LCDCONT&0x10) D0+=0x80;
  51.         P=ChrGen+(D0<<4)+Offset;
  52.         D0=*P++;D1=*P;Mask=0x80;
  53.       }
  54.     }
  55.   }
  56.       
  57.   X1=WNDPOSX-7;X2=LCDCONT&0x02;
  58.   if(((LCDCONT&0xA0)==0xA0)&&(WNDPOSY<Y)&&(X1<WIDTH))
  59.   {
  60.     R-=WIDTH-X1;
  61.     Offset=Y-WNDPOSY;
  62.     T=WndTab+((word)(Offset&0xF8)<<2);
  63.     Offset=(Offset&0x07)<<1;
  64.      
  65.     D0=*T+0x80;
  66.     P=RAM+0x8800+((word)D0<<4)+Offset;
  67.     D0=*P++;D1=*P;Mask=0x80;   
  68.   
  69.     for(;X1<WIDTH;X1++,R++)
  70.     {
  71.       *R=Palette[BPal[D0&Mask? (D1&Mask? 3:1):(D1&Mask? 2:0)]];
  72.       if(!(Mask>>=1))
  73.       {
  74.         D0=*(++T)+0x80;
  75.         P=RAM+0x8800+((word)D0<<4)+Offset;
  76.         D0=*P++;D1=*P;Mask=0x80;
  77.       }
  78.     }
  79.   }
  80. }
  81.  
  82.  
  83. /****************************************************************/
  84. /*** Refresh sprites.                                         ***/
  85. /****************************************************************/
  86. void RefreshSprites()
  87. {
  88.   register byte *P,*T,*R,*S,I,J,K,N,D0,D1;
  89.   register offset DX,DY;
  90.  
  91.   N=LCDCONT&0x04? 16:8;
  92.  
  93.   for(S=RAM+0xFE9C,J=40;J;S-=4,J--)
  94.     if(S[0]&&(S[0]<160)&&(S[1]>=8)&&(S[1]<=152))
  95.     {
  96.       if(S[0]<16) { D0=0;K=16-S[0];I=(K<N)? N-K:0; }
  97.       else        { D0=S[0]-16;K=0;I=(160-S[0]<N)? 160-S[0]:N; }
  98.       P=XBuf+D0*WIDTH+S[1]-(S[3]&0x20? 1:8);
  99.       DX=(S[3]&0x20? -1:1);DY=2;
  100.       if(S[3]&0x40) { DY=-DY;K=N-K-1; }
  101.       T=RAM+0x8000+((long)((N>8)? S[2]&0xFE:S[2])<<4)+(K<<1);
  102.       R=(S[3]&0x10)? SPal1:SPal0;
  103.  
  104.       for(;I;I--,P+=WIDTH-(DX<<3),T+=DY)
  105.         for(K=0x80,D0=*T,D1=*(T+1);K;K>>=1,P+=DX)
  106.           if((D0|D1)&K) *P=Palette[R[D0&K? (D1&K? 3:1):(D1&K? 2:0)]];
  107.     }
  108. }
  109.  
  110.  
  111. /****************************************************************/
  112. /*** Display the screen buffer.                               ***/
  113. /****************************************************************/
  114. void RefreshScreen() { PutImage(); }
  115.  
  116.